package com.joshjung.hover.levels
{
    import flash.display.Sprite;
    import com.joshjung.hover.interfaces.ILevel;
    import com.joshjung.hover.interactive.CheckPoint;
    import com.joshjung.hover.Hover;

    public class Level1 implements ILevel
    {
        protected var checkPoints : Array = [/*new CheckPoint(100, 100, 50), new CheckPoint(500, 100, 50), new CheckPoint(500, 500, 50), new CheckPoint(100, 500, 50)*/];

        protected var root : Hover;

        protected var allPassed : Boolean = false;

        public function Level1()
        {
        }

        public var _bestTime : Number = NaN;

        public function set bestTime(value : Number) : void
        {
            _bestTime = value;
        }

        public function get bestTime() : Number
        {
            return _bestTime;
        }

        public function initialize(root : Hover)
        {
            this.root = root;

            root.hoverCraft.x = 300;
            root.hoverCraft.y = 300;

            for each (var checkPoint : CheckPoint in checkPoints)
            {
                checkPoint.passed = false;
                root.canvas.addChildAt(checkPoint, 0);
            }
        }

        public function loop(elapsed : Number) : void
        {
            allPassed = true;

            for each (var checkPoint : CheckPoint in checkPoints)
            {
                if (checkPoint.hitTestPoint(root.hoverCraft.x, root.hoverCraft.y))
                {
                    checkPoint.passed = true;
                }
                else if (!checkPoint.passed)
                {
                    allPassed = false;
                }
            }
        }

        public function checkWin() : Boolean
        {
            return false;
        }
    }
}
